import { request } from "../../utils/util";
import { createStoreBindings } from 'mobx-miniprogram-bindings'
import { store } from '../../store/store'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    List: [],
    offset: 0,
    show: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.storeBindings = createStoreBindings(this, {
      store,
      actions: ['addLick']
    })
    const that = this
    request('/playlist/track/all', 'GET', {
      id: 19723756,
      limit: 10,
      offset: 0
    })
      .then(data => {
        console.log(data)
        that.setData({
          List: data.songs
        })
      })
      .catch(err => {
        console.error(err)
      })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  search: function () {
    wx.reLaunch({
      url: '../seach/seach',
    })
  },
  onChange(e) {
    this.setData({
      value: e.detail,
    });
  },
  onSearch() {
    Toast('搜索' + this.data.value);
  },
  onClick() {
    Toast('搜索' + this.data.value);
  },
  onlick(e) {
    console.log('adas数据', e.currentTarget.dataset.value);
    this.addLick(e.currentTarget.dataset.value)
  },
  onReachBottom() {
    const that = this
    request('/playlist/track/all', 'GET', {
      id: 19723756,
      limit: 10,
      offset: that.data.offset
    })
      .then(data => {
        if (data.songs.length === 0) {
          that.setData({
            show: false,
          })
        }
        console.log(data)
        let dataList = [...that.data.List, ...data.songs]
        that.setData({
          List: dataList,
          offset: that.data.offset + 10
        })
      })
      .catch(err => {
        console.error(err)
      })

  }
})